<template>
  <div class="goods-tabs">
    <nav>
      <a @click="changeTab('Detail')" href="javascript:;" :class="{ active:currContent === 'Detail' }">商品详情</a>
      <a @click="changeTab('Comment')" href="javascript:;"  :class="{ active:currContent === 'Comment' }">商品评价<span>600+</span></a>
    </nav>
    <!-- 这个位置显示对应的组件 GoodsDetail 或者 GoodsComment -->
    <!-- :is="变量" 说明：变量值是当前组件下注册的子组件的标签名 -->
    <!-- 需求： 只缓存Detail组件-->
    <keep-alive include="GoodsDetail">
      <component :is="currContent"/>
    </keep-alive>
  </div>
</template>
<script>
import { ref } from 'vue'
import Detail from './goods-detail'
import Comment from './goods-comment'
export default {
  name: 'GoodsTabs',
  components: {
    Detail,
    Comment
  },
  setup () {
    /**
     * tab选中高亮
     * 1. 定义一个标识（flag）: 1. Detail 2. Comment
     * 2. 绑定点击事件修改flag
     */
    const currContent = ref('Comment')

    // 切换标签页
    const changeTab = (curr) => {
      currContent.value = curr
    }

    return { currContent, changeTab }
  }
}
</script>
<style scoped lang="less">
.goods-tabs {
  min-height: 600px;
  background: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      > span {
        color: @priceColor;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child {
        border-right: 1px solid #f5f5f5;
      }
      &.active {
        &::before {
          content: "";
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: @xtxColor;
        }
      }
    }
  }
}
</style>
